/*
 * GrouponEntity.java
 */
package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

@Entity
public class GroupBuyingItem implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private List<Long> buyerIds; 
    private Double originalPrice;
    private Double offeredPrice;
    @Temporal(value = TemporalType.DATE)
    private Date effectiveEnd;
    @Temporal(value = TemporalType.DATE)
    private Date effectiveStart;
    @Temporal(value = TemporalType.DATE)
    private Date redemptionEnd;
    @Temporal(value = TemporalType.DATE)
    private Date redemptionStart;
    private Integer minQuota;
    private Integer maxQuota;
    private Integer personalQuota;
    private Boolean requireBooking;
    private String validateRequirements;
    private String description;
    private String name;
    private Boolean isApproved;
//    private Boolean isVoided;
    @Temporal(value = TemporalType.DATE)
    private Date submissionTime;
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private Stakeholder stakeholder;

    public GroupBuyingItem() {
        submissionTime = new Date();
    }

    public void create(
            Double originalPrice,
            Double offeredPrice,
            Date effectiveEnd,
            Date effectiveStart,
            Date redemptionEnd,
            Date redemptionStart,
            Integer minQuota,
            Integer maxQuota,
            Integer personalQuota,
            Boolean requireBooking,
            String description,
            String validateRequirements,
            String name, Stakeholder stakeholder) {
        setOriginalPrice(originalPrice);
        setOfferedPrice(offeredPrice);
        setEffectiveEnd(effectiveEnd);
        setEffectiveStart(effectiveStart);
        setRedemptionEnd(redemptionEnd);
        setRedemptionStart(redemptionStart);
        setMinQuota(minQuota);
        setMaxQuota(maxQuota);
        setPersonalQuota(personalQuota);
        setRequireBooking(requireBooking);
        setDescription(description);
        setValidateRequirements(validateRequirements);
        setName(name);
        setStakeholder(stakeholder);
//        setIsVoided(false);
        buyerIds = new ArrayList<Long>();

    }

    //return true if a user is successfully added to participant.
    public void addBuyer (Long userId) {
        buyerIds.add(userId);
    }

    public String getStatus() {
        if (this.isApproved == null) {
            return "pending";
        } else if (this.isApproved) {
            return "approved";
        } else {
            return "denied";
        }
    }

//    public String getEffectiveStartStr() {
//        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
//        Date copyDate = (Date) effectiveStart.clone();
//        return sdf.format(copyDate);
//    }

//    public String getEffectiveEndStr() {
//        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
//        Date copyDate = (Date) effectiveEnd.clone();
//        return sdf.format(copyDate);
//    }
//
//    public String getRedemptionStartStr() {
//        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
//        Date copyDate = (Date) redemptionStart.clone();
//        return sdf.format(copyDate);
//    }
//
//    public String getRedemptionEndStr() {
//        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
//        Date copyDate = (Date) redemptionEnd.clone();
//        return sdf.format(copyDate);
//    }
//
//    public String getSubmissionTimeStr(){
//        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy  hh:mm:ss");
//        Date copyDate = (Date) submissionTime.clone();
//        return sdf.format(copyDate);
//    }
    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    public List<Long> getBuyerIds() {
        return buyerIds;
    }

    public void setBuyerIds(List<Long> buyerIds) {
        this.buyerIds = buyerIds;
    }


    /**
     * @return the originalPrice
     */
    public Double getOriginalPrice() {
        return originalPrice;
    }

    /**
     * @param originalPrice the originalPrice to set
     */
    public void setOriginalPrice(Double originalPrice) {
        this.originalPrice = originalPrice;
    }

    /**
     * @return the offeredPrice
     */
    public Double getOfferedPrice() {
        return offeredPrice;
    }

    /**
     * @param offeredPrice the offeredPrice to set
     */
    public void setOfferedPrice(Double offeredPrice) {
        this.offeredPrice = offeredPrice;
    }

    /**
     * @return the redemptionEnd
     */
    public Date getRedemptionEnd() {
        return redemptionEnd;
    }

    /**
     * @param redemptionEnd the redemptionEnd to set
     */
    public void setRedemptionEnd(Date redemptionEnd) {
        this.redemptionEnd = redemptionEnd;
    }

    /**
     * @return the redemptionStart
     */
    public Date getRedemptionStart() {
        return redemptionStart;
    }

    /**
     * @param redemptionStart the redemptionStart to set
     */
    public void setRedemptionStart(Date redemptionStart) {
        this.redemptionStart = redemptionStart;
    }

    /**
     * @return the minQuota
     */
    public Integer getMinQuota() {
        return minQuota;
    }

    /**
     * @param minQuota the minQuota to set
     */
    public void setMinQuota(Integer minQuota) {
        this.minQuota = minQuota;
    }

    /**
     * @return the maxQuota
     */
    public Integer getMaxQuota() {
        return maxQuota;
    }

    /**
     * @param maxQuota the maxQuota to set
     */
    public void setMaxQuota(Integer maxQuota) {
        this.maxQuota = maxQuota;
    }

    /**
     * @return the requireBooking
     */
    public Boolean getRequireBooking() {
        return requireBooking;
    }

    /**
     * @param requireBooking the requireBooking to set
     */
    public void setRequireBooking(Boolean requireBooking) {
        this.requireBooking = requireBooking;
    }

    /**
     * @return the validateRequirements
     */
    public String getValidateRequirements() {
        return validateRequirements;
    }

    /**
     * @param validateRequirements the validateRequirements to set
     */
    public void setValidateRequirements(String validateRequirements) {
        this.validateRequirements = validateRequirements;
    }

    /**
     * @return the stakeholder
     */
    public Stakeholder getStakeholder() {
        return stakeholder;
    }

    /**
     * @param stakeholder the stakeholder to set
     */
    public void setStakeholder(Stakeholder stakeholder) {
        this.stakeholder = stakeholder;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    public Date getEffectiveEnd() {
        return effectiveEnd;
    }

    public void setEffectiveEnd(Date effectiveEnd) {
        this.effectiveEnd = effectiveEnd;
    }

    public Date getEffectiveStart() {
        return effectiveStart;
    }

    public void setEffectiveStart(Date effectiveStart) {
        this.effectiveStart = effectiveStart;
    }

    public Boolean getIsApproved() {
        return isApproved;
    }

    public void setIsApproved(Boolean isApproved) {
        this.isApproved = isApproved;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getSubmissionTime() {
        return submissionTime;
    }

    public void setSubmissionTime(Date submissionTime) {
        this.submissionTime = submissionTime;
    }
    
    

//    public Boolean getIsVoided() {
//        return isVoided;
//    }
//
//    public void setIsVoided(Boolean isVoided) {
//        this.isVoided = isVoided;
//    }
//    

    public Integer getPersonalQuota() {
        return personalQuota;
    }

    public void setPersonalQuota(Integer personalQuota) {
        this.personalQuota = personalQuota;
    }

}
